package com.travel.entity.po;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.travel.entity.dto.CarouselUploadDTO;
import com.travel.utils.Base64ToImg;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.Serializable;
import java.util.Date;

@Data
@NoArgsConstructor
@TableName("carousel")
@ApiModel(value = "轮播图实体", description = "轮播图数据表映射实体")
public class Carousel implements Serializable {
    @TableId(type = IdType.AUTO)
    @ApiModelProperty("轮播图ID")
    private Long id;
    
    @ApiModelProperty("图片URL")
    private String imgUrl;
    
    @ApiModelProperty("图片说明")
    private String caption;
    
    @ApiModelProperty("跳转链接")
    private String linkUrl;
    
    @ApiModelProperty("是否激活")
    private Integer isActive;
    
    @ApiModelProperty("图片标题")
    private String title;


    
    @Autowired
    private transient Base64ToImg base64ToImg;
    
    public Carousel(CarouselUploadDTO dto) {
        if (dto != null) {
            this.title = dto.getTitle();
            this.caption = dto.getCaption();
            this.linkUrl = dto.getLinkUrl();
            this.isActive = dto.getIsActive();

            // 静态转换base64为图片并获取URL
            if (base64ToImg != null) {
                this.imgUrl = base64ToImg.base64ToImgHerf(dto.getBase64());
            }
        }
    }
} 